/**
 * Created by liubin on 2015/9/19.
 */
'use strict';

import { SUCCESS } from 'actions/baseAction';
import { LOGIN } from 'actions/authAction';
import { ADD_ROLE } from 'actions/roleAction';
import {reducer as formReducer} from 'redux-form';

/**
 * 设置每个form的事件处理
 */
const form = formReducer.plugin(
    {
        login: (state, action) => { // <------ 'login' is name of form given to connectReduxForm()
            switch (action.type) {
                case LOGIN:
                    {
                        if (action.status === SUCCESS) {
                            // 清空输入项
                            const newState = Object.assign({}, state, {
                                username: {},
                                password: {}
                            });
                            return newState;
                        } else {
                            return state;
                        }
                    }
                default:
                    return state;
            }
        }
    }
);

export default form;